<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        h3 {
            padding: 20px 10px;
        }

        li {
            list-style: none;
        }

        .list li {
            line-height: 45px;
            text-indent: 10px;
            border: 1px solid #333;
        }

        .list li+li {
            border-top: 0;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <h3 id="title">批量操作元素</h3>
        <div class="list">
            <li>01</li>
            <li>02</li>
            <li>03</li>
            <li>04</li>
            <li>05</li>
            <li>06</li>
        </div>
        <input type="text" class="year">
    </div>
</body>
<script>
    function GetEle(selector){
        this.eles = document.querySelectorAll(selector);
    }
    GetEle.prototype.html = function(con){
        if(arguments.length >= 1){
            this.each(function(ele , index){
                ele.innerHTML = con;
            })
        }else{
            return this.eles[0].innerHTML;
        }
    }
    GetEle.prototype.text = function(con){
        if(arguments.length >= 1 ){
            this.each(function(ele, index){
                ele.innerText = con
            })
        } else { //没有参数
            return this.eles[0].innerText;
        }
    }

    GetEle.prototype.each = function (fn) {
        // this -> 调用此方法的实例化对象  {eles:[]}
        for (var i = 0; i < this.eles.length; i++) {
            var ele = this.eles[i];
            var index = i;

            //  注意  jquery中 fn(index,ele)  第一参数:下标  第二个:元素
            // fn(ele, index);   // this -> window

            fn.call(ele, ele, index);  // fn中的this指向循环当前的元素
        }

    }

    function $(selector) {
        return new GetEle(selector);
    }

    $(".list li").each(function (ele, index) {
        console.log(ele, index, this);

        // this  原生dom元素
        // this.style.background = "red";
    })


    $(".list li").html("a123123")
</script>
</html>